package sprite;
import java.awt.Image;
import java.io.Serializable;
import java.util.Vector;

public class Sprite implements Serializable{
	int x;
	int y;
	transient Vector<Image> img;
	int currentFrame;
	
	boolean visible;

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public Sprite( int x, int y ){
		this.x = x;
		this.y = y;
		img = new Vector<Image>();
		currentFrame = - 1;
	}
	
	public Sprite( int x, int y,Vector<Image> img){
		this.x = x;
		this.y = y;
		this.img = img;
		currentFrame = 0;
	}
	
	public Sprite() {
		this.x=0;
		this.y=0;
	}
	
	
	public int getWidth() {
		return img.get(currentFrame).getWidth(null);
	}
	
	public int getHeight() {
		return img.get(currentFrame).getHeight(null);
	}
	
	public boolean collideSS(Sprite s,int posx) {

			
		  if (((this.x>= posx) &&(this.x<=posx+s.img.get(s.currentFrame).getWidth(null) )) && 
				  ((this.y>= s.y) &&(this.y<=s.y+s.img.get(s.currentFrame).getHeight(null) )))   
		  {

			  return true;
		  }		
		  return false;
	}
	
	public boolean collideSD(Sprite s, int posx) {
		
		  if (((x+img.get(currentFrame).getWidth(null)>= posx) &&(x+img.get(currentFrame).getWidth(null)<=posx+s.img.get(s.currentFrame).getWidth(null) ))&&
				  ((y>= s.y) &&(y<=s.y+s.img.get(s.currentFrame).getHeight(null)  )))
		  {

			  return true;
		  }		
		  
		  return false;
	}
	
	public boolean collideID(Sprite s, int posx) {
		
		  if (((x+img.get(currentFrame).getWidth(null)>= posx) &&
				  (x+img.get(currentFrame).getWidth(null)<=posx+s.img.get(s.currentFrame).getWidth(null) ))&& 
				     ((y+img.get(currentFrame).getHeight(null)>= s.y) &&
				    		 (y+img.get(currentFrame).getHeight(null)<=s.y+s.img.get(s.currentFrame).getHeight(null)  ))) 
		  {

			  return true; 
		  }
		  	
		return false;
		
	}
	
	public boolean collideIS(Sprite s, int posx) {

		  if (((x>= posx) &&(x<=posx+s.img.get(s.currentFrame).getWidth(null) ))&& 
				     ((y+img.get(currentFrame).getHeight(null)>= s.y) &&
				    		 (y+img.get(currentFrame).getHeight(null)<=s.y+s.img.get(s.currentFrame).getHeight(null)  ))) 
		  {

			  return true;
		  }
		  
		return false;
		
	}
	
	public boolean collidesWidth(Sprite s) {
		if (collideIS(s,s.getX()) || collideSS(s,s.getX()) || collideID(s,s.getX()) || collideSD(s,s.getX())) {
			return true;
		}
		return false;

	}
	
	public boolean collidesWidthNet(Sprite s,int xpos) {
		if (collideIS(s,xpos) || collideSS(s,xpos) || collideID(s,xpos) || collideSD(s,xpos)) {
			return true;
		}
		return false;		
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
	
	public Image getImgElement(int i) {
		return img.get(i);
	}

	public Vector<Image> getImg() {
		return img;
	}

	public void setImg(Vector<Image> img) {
		this.img = img;
	}

	public int getCurrentFrame() {
		return currentFrame;
	}

	public void setCurrentFrame(int currentFrame) {
		this.currentFrame = currentFrame;
	}
	
}